package edu.hwadee.serviceImpl;

import java.util.List;

import edu.hwadee.entity.Area;
import edu.hwadee.service.AreaService;

public class AreaServiceImpl extends BasicServiceImpl implements AreaService {

	@Override
	public boolean save(Area area) {
		try {
			getAreaDAO().save(area);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean delete(Area area) {
		try {
			getAreaDAO().delete(area);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Area> search(Area area) {
		try {
			return (List<Area>)getAreaDAO().findByExample(area);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Area searchById(Integer areaId) {
		try {
			return getAreaDAO().findById(areaId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public boolean update(Area area) {
		try {
			if(searchById(area.getAreaId()) != null) {
				getAreaDAO().merge(area);
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Area> showAll() {
		try {
			return (List<Area>)getAreaDAO().findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
